

Dim doc
Set doc = application.ActiveDocument
GetUserLicence(doc)
doc.currentunit = 2
dim ObjFSO

main
sub main()
	dim userLayerName:userLayerName = "USR_PINNET"
	Dim usrLyrObj
    Set usrLyrObj = doc.FindUserLayer(userLayerName)
    If usrLyrObj Is Nothing Then
   		Set usrLyrObj = doc.SetupParameter.PutUserLayer(userLayerName)
    Else
        doc.UserLayerTexts(, userLayerName).Delete
    End If
	' TOP level
	Dim displCtrlObj
	Set displCtrlObj = doc.ActiveView.DisplayControl
	Dim dispCtrlGlobalObj
	Set dispCtrlGlobalObj = displCtrlObj.Global
	dispCtrlGlobalObj.UserLayerDisplayLevel(userLayerName) = epcbDisplayLevelTop
	dispCtrlGlobalObj.RaiseUserLayerDisplayLevel(userLayerName)
	displCtrlObj.UserLayer(userLayerName)=True
	
	if usrLyrObj is nothing then msgbox "error":exit sub
	Dim ch:ch = 2
    Dim pen:pen = 1   	
	dim selpin,selpins
	set selpins = doc.pins(1)
	'msgbox selpins.count
	for each selpin in selpins
		'msgbox selpin.net.name
		Call doc.PutUserLayerText(selpin.net.name,selpin.PositionX, selpin.PositionY, usrLyrObj,ch,0,pen,,1,,,nothing)				
	next
	
	msgbox "done"
end sub

''' 




 
'#################################################################
'#################################################################
'#################################################################
'#################################################################
' Function to validate document
Private Function ValidateServer(docObj)
    Dim key, licenseServer, licenseToken
    key = docObj.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    docObj.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

sub GetUserLicence(docObj)

	If ValidateServer(docObj) = 0 Then
	    msgbox "Server validation failed."
	    exit sub
	End If
	
end sub